package com.zjb.zjbHome.controllers.pc;

import java.util.List;

import com.jfinal.core.Controller;
import com.zjb.zjbHome.beans.model.TClassify;
import com.zjb.zjbHome.beans.model.Url;

public class Pc0001 extends Controller {

	public void index() {
		
		this.renderJsp("pc0001.html");
	}
	
	public void loadWebsiteData() {
		List<Url> listUrl = Url.dao.loadData();

		this.renderJson(listUrl);
	}
	
	public void loadClassifyData() {
		List<TClassify> listclassify = TClassify.dao.loadData();

		this.renderJson(listclassify);
	}
	
	public void search() {
		Integer classifyId = this.getParaToInt("classifyId", null);
		String websiteKey = this.getPara("websiteKey");
		
		List<Url> listUrl = Url.dao.search(websiteKey, classifyId);
		
		this.renderJson(listUrl);
	}
	
	public void deleteWebsite() {
		Integer id = this.getParaToInt("id");
		
		Boolean result = Url.dao.deleteById(id);
		
		this.renderJson(result);
	}
	
	public void addWebsite() {
		String urlName = this.getPara("urlName");
		String url = this.getPara("url");
		String introduce = this.getPara("introduce");
		Integer classifyId = this.getParaToInt("classifyId");
		
		if (!url.contains("://"))
			url = "http://" + url;
		
		Boolean result = Url.dao.addWebsite(urlName, url, introduce, classifyId);
		this.renderJson(result);
	}
	
	public void editWebsite() {
		Integer id = this.getParaToInt("id");
		String urlName = this.getPara("urlName");
		String url = this.getPara("url");
		String introduce = this.getPara("introduce");
		Integer classifyId = this.getParaToInt("classifyId");
		
		if (!url.contains("://"))
			url = "http://" + url;
		
		Boolean result = Url.dao.editWebsite(id, urlName, url, introduce, classifyId);
		this.renderJson(result);
	}
	
	public void addClassify() {
		String classifyName = this.getPara("classifyName");
		
		Boolean result = TClassify.dao.addClassify(classifyName);
		
		this.renderJson(result);
	}
	
	public void delClassify() {
		Integer id = this.getParaToInt("id");
		
		boolean result = TClassify.dao.deleteById(id);
		
		this.renderJson(result);
	}
	
	public void editclassify() {
		Integer id = this.getParaToInt("id");
		String classifyName = this.getPara("classifyName");
		
		Boolean result = TClassify.dao.editclassify(id, classifyName);
		
		this.renderJson(result);
	}
}
